//
//  UIColor+OAKit.h
//  OAKitDemo
//
//  Created by ChenJie on 8/24/20.
//  Copyright © 2020 Mist. All rights reserved.
//

#import <UIKit/UIKit.h>
#import "metamacros.h"

#define OAColor(hex...) OAColorString(hex)
#define OAColorString(hexString...) __oa_colorHexString__(hexString)
#define OAColorNumber(hexNumber...) __oa_colorHexNumber__(hexNumber)
#define OARGBColor(red, green, blue...) __oa_colorRGB__(red, green, blue)
#define OARandomColor(...) __oa_colorRandom__(__VA_ARGS__)


/* Color with hexString */
#define __oa_colorHexString__(args...) \
    metamacro_if_eq1(metamacro_argcount(args)) \
        (__oa_colorHexString_1p__(args)) \
        (__oa_colorHexString_2p__(args))

#define __oa_colorHexString_1p__(_hexString) [UIColor oa_colorWithHex:(_hexString)]
#define __oa_colorHexString_2p__(_hexString, _alpha) [UIColor oa_colorWithHex:(_hexString) alpha:(_alpha)]


/* Color with hexNumber */
#define __oa_colorHexNumber__(args...) \
    metamacro_if_eq1(metamacro_argcount(args)) \
        (__oa_colorWithHexNumber_1p__(args)) \
        (__oa_colorWithHexNumber_2p__(args))

#define __oa_colorWithHexNumber_1p__(_hexNumber) [UIColor oa_colorWithHexNumber:(0x##_hexNumber)]
#define __oa_colorWithHexNumber_2p__(_hexNumber, _alpha) [UIColor oa_colorWithHexNumber:(0x##_hexNumber) alpha:(_alpha)]


/* Color with rgb */
#define __oa_colorRGB__(args...) \
    metamacro_if_eq3(metamacro_argcount(args)) \
        (__oa_colorRGB_3p__(args)) \
        (__oa_colorRGB_4p__(args))

#define __oa_colorRGB_3p__(_red, _green, _blue) [UIColor oa_colorWithRed:(_red) green:(_green) blue:(_blue)]
#define __oa_colorRGB_4p__(_red, _green, _blue, _alpha) [UIColor oa_colorWithRed:(_red) green:(_green) blue:(_blue) alpha:(_alpha)]


/* Color with random */
#define __oa_colorRandom__(args...) __oa_colorRandom_add_1p__(1, ##args)

#define __oa_colorRandom_add_1p__(args...) \
    metamacro_if_eq1(metamacro_argcount(args)) \
        (__oa_colorRandom_0p__()) \
        (__oa_colorRandom_1p__(metamacro_at1(args)))

#define __oa_colorRandom_0p__() [UIColor oa_randomColor]
#define __oa_colorRandom_1p__(_alpha) [UIColor oa_randomColorWithAlpha:(_alpha)]

@interface UIColor (OAKit)

/* hex string */
+ (instancetype)oa_colorWithHex:(NSString *)hexString;
+ (instancetype)oa_colorWithHex:(NSString *)hexString alpha:(CGFloat)alpha;

/* hex number */
+ (instancetype)oa_colorWithHexNumber:(NSUInteger)hexNumber;
+ (instancetype)oa_colorWithHexNumber:(NSUInteger)hexNumber alpha:(CGFloat)alpha;

/* rgb */
+ (instancetype)oa_colorWithRed:(NSInteger)red green:(NSInteger)green blue:(NSInteger)blue;
+ (instancetype)oa_colorWithRed:(NSInteger)red green:(NSInteger)green blue:(NSInteger)blue alpha:(CGFloat)alpha;

/* random */
+ (instancetype)oa_randomColor;
+ (instancetype)oa_randomColorWithAlpha:(CGFloat)alpha;

@end

